import {LogLanguage} from "../dist/index.js"

// 测试字符串识别
const testCase = 'INFO User "john_doe" logged in'

console.log("Debugging string recognition...")
console.log(`Input: ${testCase}`)

try {
  const tree = LogLanguage.parser.parse(testCase)
  console.log("✅ Parse successful!")
  
  // 检查所有节点
  console.log("\nAll nodes:")
  tree.iterate({
    enter: (node) => {
      const text = testCase.slice(node.from, node.to)
      console.log(`- ${node.name}: "${text}" (${node.from}-${node.to})`)
    }
  })
  
  // 特别检查字符串相关节点
  console.log("\nLooking for String-related nodes:")
  let foundString = false
  tree.iterate({
    enter: (node) => {
      if (node.name === "StringLiteral") {
        foundString = true
        const text = testCase.slice(node.from, node.to)
        console.log(`Found StringLiteral: "${text}"`)
      }
    }
  })
  
  if (!foundString) {
    console.log("❌ No string nodes found")
    
    // 检查是否有引号
    const hasQuotes = testCase.includes('"') || testCase.includes("'") || testCase.includes('`')
    console.log(`Has quotes: ${hasQuotes}`)
    
    // 检查INFO是否被识别
    let hasInfo = false
    tree.iterate({
      enter: (node) => {
        if (node.name === "INFOExpression") {
          hasInfo = true
          const text = testCase.slice(node.from, node.to)
          console.log(`Found INFOExpression: "${text}"`)
        }
      }
    })
    
    if (!hasInfo) {
      console.log("❌ INFOExpression not found either")
    }
  }
  
} catch (error) {
  console.log(`❌ Parse failed: ${error.message}`)
} 